/**
 * @param {number} n
 * @param {number} k
 * @return {number[][]}
 */
var combine = function (n, k) {
  const res = []
  const path = []

  function backTrack(path, startIndex) {
      if (path.length === k) {
          res.push([...path])
          return
      }

      for (let i = startIndex; i <= n; i++) {
          path.push(i)
          backTrack(path, i + 1)
          path.pop()
      }
  }
  backTrack(path, 1)
  return res
};